package com.briup.pai.common.utils;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;

public class MessageUtil {

    public static final String ACCESS_KET_ID = "LTAI5tMYXL2a3FVNoG4yFhZ4";
    public static final String ACCESS_KEY_SECRET = "0AIUSZXtNzeGt4Aonu6uEXSkAQ62jG";
    public static final String ENDPOINT = "dysmsapi.aliyuncs.com";

    public static void sendMessage(String telephone, Integer code) throws Exception{
        // 创建配置信息
        Config config = new Config()
                // 密钥ID
                .setAccessKeyId(ACCESS_KET_ID)
                // 密钥
                .setAccessKeySecret(ACCESS_KEY_SECRET)
                // 地区信息
                .setEndpoint(ENDPOINT);
        // 创建客户端对象
        Client client = new Client(config);
        // 创建发送消息请求对象
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setSignName("阿里云短信测试")
                .setTemplateCode("SMS_327347165")
                .setPhoneNumbers(telephone)
                .setTemplateParam("{\"code\":" + code + "}");
        RuntimeOptions runtime = new RuntimeOptions();
        // 发送消息
        client.sendSmsWithOptions(sendSmsRequest, runtime);
    }

    public static void main(String[] args) throws Exception {
        MessageUtil.sendMessage("19951154250", 8888);
    }
}